package com.gisquest.cloud.api;

import com.gisquest.cloud.entity.po.BizLogEntity;
import com.gisquest.cloud.entity.vo.PageVo;
import com.gisquest.cloud.entity.vo.RequestEntity;
import com.gisquest.cloud.entity.vo.RestResult;
import com.gisquest.cloud.entity.vo.SysLogVO;
import com.gisquest.cloud.service.EsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author guowei
 * @Date 2020/6/19 10:36
 * @Description:
 **/
@RestController
@RequestMapping("/es")
@Api(value = "调用esAPI的管理", tags = "调用esAPI的管理")
public class EsController {

  @Autowired
  EsService esService;

  /**
   * 直接将业务日志存储到es
   * @param bizLogEntity 业务日志对象
   * @return
   */
  @ApiOperation(value = "直接添加业务日志信息到es", notes = "add by gw 2020-06-23")
  @PostMapping("/saveBizLogToEs")
  public RestResult<?> saveBizLogToEs(@ApiParam("请求参数对象") @RequestBody BizLogEntity bizLogEntity){
    return esService.saveBizLogToEs(bizLogEntity);
  }

  /**
   * 分页查询es中的业务日志信息
   * @param requestEntity 请求对象
   * @param pageVo 页码信息
   * @return
   */
  @ApiOperation(value = "从es查询业务日志信息", notes = "add by gw 2020-06-23")
  @GetMapping("/getBizLogFromEs")
  public RestResult<?> getBizLogFromEs(@ApiParam("请求参数对象")  @RequestBody RequestEntity requestEntity, @ApiParam("分页参数")  @RequestBody PageVo pageVo){
    return esService.getBizLogFromEs(requestEntity,pageVo);
  }

  /**
   * 直接将系统日志写入es
   * @param sysLogVO
   * @return
   */
  @ApiOperation(value = "直接添加系统日志信息到es", notes = "add by gw 2020-06-23")
  @PostMapping("/saveSysLogToEs")
  public RestResult<?> saveSysLogToEs(@ApiParam("请求参数对象") @RequestBody SysLogVO sysLogVO){
    return esService.saveSysLogToEs(sysLogVO);
  }

  /**
   * 从es查询系统日志
   * @param sysLogVO
   * @param pageVo
   * @return
   */
  @ApiOperation(value = "从es查询系统日志信息", notes = "add by gw 2020-06-23")
  @GetMapping("/getSysLogFromEs")
  public RestResult<?> getSysLogFromEs(@ApiParam("请求参数对象") @RequestBody SysLogVO sysLogVO, @ApiParam("分页参数") @RequestBody PageVo pageVo){
    return esService.getSysLogFromEs(sysLogVO,pageVo);
  }


  /**
   * 添加系统日志信息到redis，在由logstash抽取存入es
   * @param sysLogVO
   * @return
   */
  @ApiOperation(value = "添加系统日志信息到redis", notes = "add by gw 2020-06-24")
  @PostMapping("/saveSysLogToRs")
  public RestResult<?> saveSysLogToRs(@ApiParam("请求参数对象") @RequestBody SysLogVO sysLogVO){
    return esService.saveSysLogToRs(sysLogVO);
  }

  /**
   * 添加业务日志信息到redis，在由logstash抽取存入es
   * @param bizLogEntity
   * @return
   */
  @ApiOperation(value = "添加业务日志信息到redis", notes = "add by gw 2020-06-24")
  @PostMapping("/saveBizLogToRs")
  public RestResult<?> saveBizLogToRs(@ApiParam("请求参数对象") @RequestBody BizLogEntity bizLogEntity){
    return esService.saveBizLogToRs(bizLogEntity);
  }

}
